home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 8
/
FM Towns Free Software Collection 8.iso
/
t_os
/
pao
/
pvs_pvd
/
src
/
fontfile.c
< prev
next >
Wrap
Text File
|
1994-06-01
|
6KB
|
198 lines
/* << HighC V1.7 >> [FM-TOWNS] **********************************************
*
* フォントファイル処理
* ----------------------------------------------------------------------
* Programmed by Y.Hirata ( NIFTY-ID: NAB03321 パオパオ )
*
* NOTE: TAB=4
****************************************************************************/
#include <ctype.h> /* islower */
#include <string.h> /* str*,mem* */
#include "egbtxt.h" /* FNT,EGB */
#define TRUE 1
#define FALSE 0
const char *FONT1[] = { "MINN", "GOTH", "KYOU", "MARU", "MOUH" } ;
const char *FONTS[] = { "24", "32", "48", "60" } ;
const char *FONT2[] = { "", "HH", "HK", "QH", "QK" } ;
const int FONTSZ[] = { 72, 128, 288, 480 } ;
const char *TYPENAME[] = { "FONT ",
"FONT1 ",
"FONT2 "
} ;
char FontPath[NFONT2][_MAX_PATH] ; /* フォントファイルパス */
char FontData[64/8*60] ; /* フォント読み込み用 */
int FontType ; /* フォントファイル種別 */
int FontNo ; /* フォント種別 */
int FontDots=24 ; /* フォントサイズ(dots) */
int FontSize=72 ; /* フォントサイズ(byte) */
int FontSizeNo=0 ; /* フォントサイズNo. */
FILE *FontFp[NFONT2] = { NULL } ; /* フォントファイルポインタ */
void strupper( char *str )
/*===========================================================================
* 文字列中の小文字を大文字に変換
===========================================================================*/
{
register int cnt ;
for ( cnt=0; cnt<strlen( str ); cnt++ ) { /* 小文字 -> 大文字 */
if ( iskanji( str[cnt] ) ) {
cnt++ ;
} else {
if ( islower( str[cnt] ) ) str[cnt] -= ' ' ;
}
}
}
void makeFontPath( void )
/*===========================================================================
* フォントファイルのフルパスを作成
===========================================================================*/
{
register int cp, term=FALSE ;
int len ;
char *path ;
strcpy( FontPath[0],"" ) ;
if ( (path=getenv( "FNT" )) != NULL ) { /* 環境変数'FNT=' */
len = strlen( path ) ;
if ( path[len-1] == '\\' ) {
for ( cp=0; cp<len; cp++ ) {
if ( iskanji( path[cp] ) ) { /* 漢字 */
term = FALSE ;
++cp ;
} else {
term = TRUE ;
}
}
}
strcpy( FontPath[0],path ) ;
strupper( FontPath[0] ) ;
if ( !term ) {
FontPath[0][len] = '\\' ; /* '\'の追加 */
FontPath[0][len+1] = '\0' ;
}
}
strcat( FontPath[0],FONT1[FontNo] ) ;
strcat( FontPath[0],FONTS[FontSizeNo] ) ;
for ( cp=1; cp<NFONT2; cp++ ) {
strcpy( FontPath[cp],FontPath[0] ) ;
strcat( FontPath[cp],FONT2[cp] ) ;
}
strcat( FontPath[0],FONT2[0] ) ;
for ( cp=0; cp<NFONT2; cp++ ) strcat( FontPath[cp],".FNT" ) ;
}
int chkFontFile( void )
/*===========================================================================
* フォントファイル種別のチェック
===========================================================================*/
{
register int cnt ;
char type[8] ;
if ( FontFp[0] == NULL ) {
FontType = -1 ;
return 1 ;
}
rewind( FontFp[0] ) ;
if ( fread( type,1,8,FontFp[0] ) == 8 ) {
for ( cnt=0; cnt<NTYPE; cnt++ ) {
if ( !memcmp( type,TYPENAME[cnt],8 ) ) {
FontType = cnt ;
return 0 ;
}
}
}
FontType = -1 ;
return 1 ;
}
int getFontOffset( int *sjis )
/*===========================================================================
* フォントファイル中のオフセット
===========================================================================*/
{
char h, l ;
int size=FontSize ;
int hsize=16 ;
*sjis = FNT_sjisToJis( *sjis ) ;
l = *sjis & 0xFF ;
if ( l < 0x21 || l > 0x7E ) return -1 ;
h = (unsigned short int)*sjis >> 8 ;
if ( h < 0x21 || h > 0x74 ) return -1 ;
switch ( FontType ) {
case 0:
case 1: size += 2 ; break ;
case 2: hsize += ( size * 128 ) ;
}
return ( ( (h-0x21) * 94 + (l-0x21) ) * size + hsize ) ;
}
int loadFont( FILE *fp,int code,int kanji )
/*===========================================================================
* フォントの読み込み
===========================================================================*/
{
register int ch, size=FontSize ;
if ( FontType == 0 || FontType == 1 ) {
ch = fgetc( fp ) << 8 ;
ch |= fgetc( fp ) ;
if ( feof( fp ) ) return 1 ;
if ( ch != code ) return 2 ;
} else {
if ( !kanji ) size /= 2 ;
}
if ( fread( FontData,1,size,fp ) < size ) return 3 ;
return 0 ;
}
int fontOpen( int fno,int dots )
/*===========================================================================
* フォントファイルオープン
* < RET > : 設定条件に誤りがなければ 0, 誤りならば 1 を返す.
===========================================================================*/
{
int cnt ;
if ( fno < 0 || fno > F_MOUH ) return 1 ;
for ( cnt=0; cnt<NSIZE; cnt++ ) {
if ( atoi( FONTS[cnt] ) == dots ) break;
}
if ( cnt >= NSIZE ) return 1 ;
FontSizeNo = cnt ; /* フォントサイズ種別 */
FontNo = fno ; /* フォント種別 */
FontDots = dots ; /* ドットサイズ */
FontSize = FONTSZ[FontSizeNo] ; /* フォントデータサイズ */
makeFontPath() ; /* フォントファイルのパス作成 */
for ( cnt=0; cnt<NFONT2; cnt++ ) {
if ( FontFp[cnt] != NULL ) fclose( FontFp[cnt] ) ;
FontFp[cnt] = fopen( FontPath[cnt],"rb" ) ;
}
chkFontFile() ; /* フォントファイルの種別チェック */
return 0 ;
}
void fontClose( void )
/*===========================================================================
* フォントファイルクローズ
===========================================================================*/
{
int cnt ;
for ( cnt=0; cnt<NFONT2; cnt++ )
if ( FontFp[cnt] != NULL ) fclose( FontFp[cnt] ) ;
}
/* HISTORY
-----------------------------------------------------------------------------
* 1991.04.13 : CREATE
* 1993.08.09 : remake
---------------------------------------------------------------------------*/